package com.example.demo.repository;

import com.example.demo.model.Student;
import org.aspectj.lang.annotation.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class StudentRepositoryTest {

    @Autowired
    private StudentRepository  studentRepository;

    @BeforeEach
    void setUp() {
        Student s = new Student();

        s.setName("Jack");

        studentRepository.save(s);
    }

    @Test
    void findByName() {
        List<Student> students = studentRepository.findByName("Jack");

        Assertions.assertNotNull(students);

        Assertions.assertEquals(1, students.size());
    }

    @AfterEach
    void tearDown() {
        List<Student> students = studentRepository.findByName("Jack");

        studentRepository.deleteAll(students);
    }
}